package io.pisceshub.muchat.connector.remote.netty.ws.endecode;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import io.pisceshub.muchat.common.core.model.IMSendInfo;

import java.util.List;

public class MessageProtocolDecoder extends MessageToMessageDecoder<TextWebSocketFrame> {

  @Override
  protected void decode(ChannelHandlerContext channelHandlerContext,
      TextWebSocketFrame textWebSocketFrame,
      List<Object> list) throws Exception {
    ObjectMapper objectMapper = new ObjectMapper();
    IMSendInfo sendInfo = objectMapper.readValue(textWebSocketFrame.text(), IMSendInfo.class);
    list.add(sendInfo);
  }
}
